<?xml version="1.0" encoding="UTF-8"?>

<xs:schema id="schema.spa"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://a42.vodafone.com/versions/spa/v1"
    xmlns:a42ns="http://a42.vodafone.com/versions/a42/v1"
    xmlns:sc2ns="http://a42.vodafone.com/versions/sc2/v1"
    xmlns:sphns="http://a42.vodafone.com/versions/sph/v1"
    xmlns:spans="http://a42.vodafone.com/versions/spa/v1"
    elementFormDefault="qualified"
    >
    
    <!-- Import the common types for A42 resources. -->
    <!-- <xs:include schemaLocation="a42.xsd" /> -->
    <xs:import schemaLocation="a42.xsd" namespace="http://a42.vodafone.com/versions/a42/v1" />
    <!-- Import the referenced types for simple content catalog resources. -->
    <!-- <xs:include schemaLocation="sc2.xsd" /> -->
    <xs:import schemaLocation="sc2.xsd" namespace="http://a42.vodafone.com/versions/sc2/v1" />
    <!-- Import the referenced types for simple purchase API resources. -->
    <!-- <xs:include schemaLocation="sph.xsd" /> -->
    <xs:import schemaLocation="sph.xsd" namespace="http://a42.vodafone.com/versions/sph/v1" />
    
    <xs:defaultOpenContent mode="interleave">
        <xs:any namespace="##any" processContents="lax" />
    </xs:defaultOpenContent>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Definition of XML representations for purchase history resources and related DTOs. -->
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <!-- Specific link types with defined link relation types. -->
    <xs:complexType name="orderDirectoriesLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/orderDirectories" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="orderDirectoryLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/orderDirectory" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchaseOrdersLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/purchaseOrders" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchaseOrderLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/purchaseOrder" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchaseOrderCancellationLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/cancellation" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchaseOrderPaymentLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/payment" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="lineItemsLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/lineItems" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="lineItemLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/lineItem" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <!-- Representation for the service document for this API. -->
    <xs:element name="spaServiceDocument">
        <xs:complexType>
            <xs:all>
                <!-- Root link for provisioning and deprovisioning only for admin authorization. -->
                <xs:element name="orderDirectoriesRootLink" type="spans:orderDirectoriesLinkType" minOccurs="0" maxOccurs="1" />
                <!-- Root link for particular purchase history only for a provisioned user. -->
                <xs:element name="orderDirectoryRootLink" type="spans:orderDirectoryLinkType" minOccurs="0" maxOccurs="1" />
            </xs:all>
        </xs:complexType>
    </xs:element>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <xs:element name="orderDirectories" type="spans:orderDirectoriesType" />
    <xs:complexType name="orderDirectoriesType">
        <xs:complexContent>
            <xs:extension base="a42ns:PaginatableResourceType">
                <xs:all>
                    <xs:element name="orderDirectories" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="link" type="spans:orderDirectoryLinkType" />
                                <xs:element name="orderDirectory" type="spans:orderDirectoryType" />
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:element name="purchaseOrders" type="spans:purchaseOrdersType" />
    <xs:complexType name="purchaseOrdersType">
        <xs:complexContent>
            <xs:extension base="a42ns:PaginatableResourceType">
                <xs:all>
                    <xs:element name="purchaseOrders" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="link" type="spans:purchaseOrderLinkType" />
                                <xs:element name="purchaseOrder" type="spans:purchaseOrderType" />
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:element name="lineItems" type="spans:lineItemsType" />
    <xs:complexType name="lineItemsType">
        <xs:complexContent>
            <xs:extension base="a42ns:PaginatableResourceType">
                <xs:all>
                    <xs:element name="lineItems" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="link" type="spans:lineItemsLinkType" />
                                <xs:element name="purchaseOrder" type="spans:lineItemsType" />
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <xs:complexType name="embeddedPurchaseOrdersType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="spans:purchaseOrdersLinkType" />
            <xs:element name="purchaseOrders" type="spans:purchaseOrdersType" />
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="embeddedPurchaseOrderType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="spans:purchaseOrderLinkType" />
            <xs:element name="purchaseOrder" type="spans:purchaseOrderType" />
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="embeddedLineItemsType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="spans:lineItemsLinkType" />
            <xs:element name="lineItems" type="spans:lineItemsType" />
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="embeddedLineItemType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="spans:lineItemLinkType" />
            <xs:element name="lineItem" type="spans:lineItemType" />
        </xs:choice>
    </xs:complexType>
    
    <xs:element name="orderDirectory" type="spans:orderDirectoryType" />
    <xs:complexType name="orderDirectoryType">
        <xs:complexContent>
            <xs:extension base="a42ns:ResourceType">
                <xs:all>
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <xs:element name="purchaseOrders" type="spans:embeddedPurchaseOrdersType" minOccurs="0" maxOccurs="1"/>
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:element name="purchaseOrder" type="spans:purchaseOrderType" />
    <xs:complexType name="purchaseOrderType">
        <xs:complexContent>
            <xs:extension base="a42ns:PaginatableResourceType">
                <xs:all>
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <!-- Shall contain payment and canellation links. -->
                    <xs:element name="links" type="a42ns:LinkArrayType" minOccurs="1" maxOccurs="1"/>
                    <!-- <xs:element name="cancellation" type="spans:purchaseOrderCancellationLinkType" minOccurs="0" maxOccurs="1" /> -->
                    <!-- <xs:element name="payment" type="spans:purchaseOrderPaymentLinkType" minOccurs="0" maxOccurs="1" /> -->
                    <xs:element name="totalPrice" type="xs:double" minOccurs="0" maxOccurs="1" />
                    <xs:element name="currency" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <xs:element name="lineItems" minOccurs="0" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="link" type="spans:lineItemLinkType" />
                                <xs:element name="lineItem" type="spans:lineItemType" />
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                    <xs:element name="purchaseHistory" type="sphns:embeddedPurchaseHistoryType" minOccurs="0" maxOccurs="1" />
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:element name="lineItem" type="spans:lineItemType" />
    <xs:complexType name="lineItemType">
        <xs:complexContent>
            <xs:extension base="a42ns:ResourceType">
                <xs:all>
                    <xs:element name="purchaseOrder" type="spans:embeddedPurchaseOrderType" minOccurs="0" maxOccurs="1"/>
                    <xs:element name="catalogItem" type="sc2ns:embeddedCatalogItemType" minOccurs="0" maxOccurs="1" />
                    <!-- After a payment was successfully done, the purchased items are referenced. -->
                    <xs:element name="purchasedItems" type="sphns:embeddedPurchasedItemsType" minOccurs="0" maxOccurs="1"/>
                    <xs:element name="purchasedItem" type="sphns:embeddedPurchasedItemType" minOccurs="0" maxOccurs="1"/>
                    <xs:element name="amount" type="xs:int" minOccurs="0" maxOccurs="1" />
                    <xs:element name="unitPrice" type="xs:double" />
                    <xs:element name="lineItemPrice" type="xs:double" />
                    <!-- The currency used to execute the purchase. -->
                    <xs:element name="currency" type="xs:string" minOccurs="0" maxOccurs="1" />
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
</xs:schema>
